import { Strategy, StrategyOptions, ExtractJwt } from "passport-jwt"
import { PassportStrategy } from '@nestjs/passport';
import { InjectModel } from "nestjs-typegoose";
import { User } from "@libs/db/models/user.models";
import { ProjectConfig } from './auth.config';
import { ModelType } from "@typegoose/typegoose/lib/types";

export class jwtStrategy extends PassportStrategy(Strategy, "jwt") {
    constructor(@InjectModel(User) private userModel: ModelType<User>) {

        super({
            jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
            ignoreExpiration: false,
            secretOrKey: ProjectConfig.SECRET
        } as StrategyOptions)
    }

    async validate({ data }) {
        return await this.userModel.findById(data)

    }

} 